import axios from 'axios'
import {Indicator, Toast} from 'mint-ui';

//创建axios实例
const service = axios.create({
    timeout: 50000, // 请求超时时间
})

//request拦截器
service.interceptors.request.use(config => {
    Indicator.open({
        spinnerType: 'fading-circle'
    });
    config.headers = {'Content-Type': "application/x-www-form-urlencoded"};
    console.log('config ', config)
    return config
}, error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
})

//respone拦截器
service.interceptors.response.use(
    response => {
        Indicator.close();
        let res = response.data;
        console.log(res);
        if (res['respCode'] != '100200') {
            Toast({
                message: res['respMsg'],
                position: 'middle'
            });
        }
        return response.data
    },
    error => {
        return Promise.reject(error)
    }
)

export default service
